home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / signal.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  140 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: signal.c,v 1.5 1996/10/24 15:50:58 aros Exp $
  4.     $Log: signal.c,v $
  5.     Revision 1.5  1996/10/24 15:50:58  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:56:09  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:20  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang: english
  18. */
  19. #include <exec/execbase.h>
  20. #include <aros/libcall.h>
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <clib/exec_protos.h>
  26.  
  27.     AROS_LH2(void, Signal,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(struct Task *,     task,      A1),
  31.     AROS_LHA(ULONG,             signalSet, D0),
  32.  
  33. /*  LOCATION */
  34.     struct ExecBase *, SysBase, 54, Exec)
  35.  
  36. /*  FUNCTION
  37.     Send some signals to a given task. If the task is currently waiting
  38.     on these signals, has a higher priority as the current one and if
  39.     taskswitches are allowed the new task begins to run immediately.
  40.  
  41.     INPUTS
  42.     task      - Pointer to task structure.
  43.     signalSet - The set of signals to send to the task.
  44.  
  45.     RESULT
  46.  
  47.     NOTES
  48.     This function may be used from interrupts.
  49.  
  50.     EXAMPLE
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.     AllocSignal(), FreeSignal(), Wait(), SetSignal(), SetExcept()
  56.  
  57.     INTERNALS
  58.  
  59.     HISTORY
  60.  
  61. ******************************************************************************/
  62. {
  63.     AROS_LIBFUNC_INIT
  64.  
  65.     /* Protect the task lists against other tasks that may use Signal(). */
  66.     Disable();
  67.  
  68.     /* Set the signals in the task structure. */
  69.     task->tc_SigRecvd|=signalSet;
  70.  
  71.     /* Do those bits raise exceptions? */
  72.     if(task->tc_SigExcept&task->tc_SigRecvd)
  73.     {
  74.     /* Yes. Set the exception flag. */
  75.     task->tc_Flags|=TF_EXCEPT;
  76.  
  77.     /* task is running? Raise the exception or defer it for later. */
  78.     if(task->tc_State==TS_RUN)
  79.     {
  80.         /* Are taskswitches allowed? (Don't count own Disable() here) */
  81.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  82.         /* No. Store it for later. */
  83.         SysBase->AttnResched|=0x80;
  84.         else
  85.         {
  86.         /* Switches are allowed. Move the current task away. */
  87.         SysBase->ThisTask->tc_State=TS_READY;
  88.         Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  89.  
  90.         /* And force a rescedule. */
  91.         Switch();
  92.         }
  93.  
  94.         /* All done. */
  95.         Enable();
  96.         return;
  97.     }
  98.     }
  99.  
  100.     /*
  101.     Is the task receiving the signals waiting on them
  102.     (or on a exception) ?
  103.     */
  104.     if(task->tc_State==TS_WAIT&&
  105.        (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
  106.     {
  107.     /* Yes. Move him to the ready list. */
  108.     task->tc_State=TS_READY;
  109.     Remove(&task->tc_Node);
  110.     Enqueue(&SysBase->TaskReady,&task->tc_Node);
  111.  
  112.     /* Has it a higher priority as the current one? */
  113.     if(task->tc_Node.ln_Pri>SysBase->ThisTask->tc_Node.ln_Pri)
  114.         /*
  115.         Yes. A taskswitch is necessary. Prepare one if possible.
  116.         (If the current task is not running it is already moved)
  117.         */
  118.         if(SysBase->ThisTask->tc_State==TS_RUN)
  119.         {
  120.         /* Are taskswitches allowed? */
  121.         if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
  122.             /* No. Store it for later. */
  123.             SysBase->AttnResched|=0x80;
  124.         else
  125.         {
  126.             /* Switches are allowed. Move the current task away. */
  127.             SysBase->ThisTask->tc_State=TS_READY;
  128.             Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  129.  
  130.             /* And force a rescedule. */
  131.             Switch();
  132.         }
  133.         }
  134.     }
  135.  
  136.     Enable();
  137.     AROS_LIBFUNC_EXIT
  138. }
  139.  
  140.